package com.yeban.javase.day19.answer.test4;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Desc 自定义线程池
 * @Author yeban
 * @Date 2025/11/4
 */
public class ThreadPool {

    private ThreadPoolExecutor threadPoolExecutor;

    public ThreadPool(int maxPoolSize, int queueSize) {
        threadPoolExecutor = new ThreadPoolExecutor(
                3 , maxPoolSize , 60 , TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(queueSize),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }

    // 执行方法
    public void execute(Runnable runnable) {
        threadPoolExecutor.submit(runnable);
    }

    // 关闭方法
    public void close() {
        threadPoolExecutor.shutdown();
    }
}
